package clue

import (
	"context"
	"git.mycaigou.com/gfyx/common/rpc_client"
	"git.mycaigou.com/gfyx/micro-gfyx-mp-api/infrastructure/common/constants"
	cluePb "git.mycaigou.com/gfyx/micro-gfyx-mp-api/proto/micro_gfyx_oppty_service_proto/micro-gfyx-oppty-service/clue"
)

type clueRepository struct {
}

// NewClueRepository
// 线索管理
func NewClueRepository() ClueRepositoryIface {
	return &clueRepository{}
}

func (r *clueRepository) GetInChargeUserList(ctx context.Context, request *cluePb.GetInChargeUserListRequest) (*cluePb.GetInChargeUserListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.GetInChargeUserList(ctx, request)
}

func (r *clueRepository) GetClueList(ctx context.Context, request *cluePb.GetClueListRequest) (*cluePb.GetClueListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.GetClueList(ctx, request)
}

func (r *clueRepository) GetClueDetail(ctx context.Context, request *cluePb.GetClueDetailByClueIdRequest) (*cluePb.GetClueDetailByClueIdResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.GetClueDetailByClueId(ctx, request)
}

func (r *clueRepository) SaveClue(ctx context.Context, request *cluePb.SaveClueRequest) (*cluePb.SaveClueResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.SaveClue(ctx, request)
}

func (r *clueRepository) SaveClueTracker(ctx context.Context, request *cluePb.SaveClueTrackerRequest) (*cluePb.SaveClueTrackerResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.SaveClueTracker(ctx, request)
}

func (r *clueRepository) GetClueTrackerList(ctx context.Context, request *cluePb.GetClueTrackerListRequest) (*cluePb.GetClueTrackerListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.GetClueTrackerList(ctx, request)
}

func (r *clueRepository) DeleteClueTracker(ctx context.Context, request *cluePb.DeleteClueTrackerRequest) (*cluePb.DeleteClueTrackerResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.DeleteClueTracker(ctx, request)
}

func (r *clueRepository) ReplaceChargeUser(ctx context.Context, request *cluePb.ReplaceChargeUserRequest) (*cluePb.ReplaceChargeUserResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.ReplaceChargeUser(ctx, request)
}

func (r *clueRepository) SaveClueContact(ctx context.Context, request *cluePb.SaveClueContactRequest) (*cluePb.SaveClueContactResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.SaveClueContact(ctx, request)
}

func (r *clueRepository) DeleteClueContact(ctx context.Context, request *cluePb.DeleteClueContactRequest) (*cluePb.DeleteClueContactResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.DeleteClueContact(ctx, request)
}

func (r *clueRepository) GetClueContactList(ctx context.Context, request *cluePb.GetClueContactListRequest) (*cluePb.GetClueContactListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.GetClueContactList(ctx, request)
}

func (r *clueRepository) GetClueContactDetailById(ctx context.Context, request *cluePb.GetClueContactDetailByIdRequest) (*cluePb.GetClueContactDetailByIdResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.GetClueContactDetailById(ctx, request)
}

func (r *clueRepository) DeleteClue(ctx context.Context, request *cluePb.DeleteClueRequest) (*cluePb.DeleteClueResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.DeleteClue(ctx, request)
}

func (r *clueRepository) AddClueFollowRecord(ctx context.Context, request *cluePb.AddClueFollowRecordRequest) (*cluePb.AddClueFollowRecordResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.AddClueFollowRecord(ctx, request)
}

func (r *clueRepository) GetClueFollowRecordList(ctx context.Context, request *cluePb.GetClueFollowRecordListRequest) (*cluePb.GetClueFollowRecordListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.GetClueFollowRecordList(ctx, request)
}

func (r *clueRepository) AddClueSourceFollow(ctx context.Context, request *cluePb.AddClueSourceFollowRequest) (*cluePb.AddClueSourceFollowResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.AddClueSourceFollow(ctx, request)
}

func (r *clueRepository) ExportClueList(ctx context.Context, request *cluePb.ExportClueListRequest) (*cluePb.ExportClueListResponse, error) {
	conn, ctx, err := rpc_client.GetClientConn(ctx, constants.MICRO_GFYX_OPPTY_SERVICE)
	if err != nil {
		return nil, err
	}
	defer func() {
		_ = conn.Close()
	}()
	client := cluePb.NewClueServiceClient(conn)
	return client.ExportClueList(ctx, request)
}
